package com.ai.chinamobileai.config;

import jakarta.annotation.PostConstruct;
import org.springframework.ai.document.Document;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class VectorStoreDataLoader {
    
    private final JsonReader jsonReader;
    private final VectorStore vectorStore;
    private final OpenAiEmbeddingModel embeddingModel;
    
    public VectorStoreDataLoader(JsonReader jsonReader, VectorStore vectorStore, 
                               OpenAiEmbeddingModel embeddingModel) {
        this.jsonReader = jsonReader;
        this.vectorStore = vectorStore;
        this.embeddingModel = embeddingModel;
    }
    
    @PostConstruct
    public void loadJsonDataToVectorStore() {
        // 读取JSON数据
        List<Document> documents = jsonReader.get();
        
        // 将文档添加到向量存储中
        vectorStore.add(documents);
    }
}
